# 计分牌
import pygame
from .infoBar import InfoBar
from .eventCenter import EventCenter


class InfoBarConfig:
    def __init__(self, msg, x=0, y=0):
        self.msg = msg
        self.x = x
        self.y = y


class ScoreBar(EventCenter):

    def __init__(self, screen):
        
        self.screen = screen
        self.store = []
        self.registered('gameBlit', lambda e: self.blitme())    


    def add(self, config, eventName, updateFn):
        
        item = InfoBar(self.screen, config.msg, config.x, config.y)
        self.store.append(item)
        self.registered(eventName, lambda e: updateFn(item, e))
    
    def remove(self, infoBar):
        self.store.remove(infoBar)
    
    def blitme(self):
        for item in self.store:
            item.blitme()

    def clear(self):
        self.store.clear()